<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Coupon extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'coupon';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'coupon_type_text',
        'expire_type_text',
        'status_text'
    ];
    

    
    public function getCouponTypeList()
    {
        return ['1' => __('Coupon_type 1'), '2' => __('Coupon_type 2')];
    }

    public function getExpireTypeList()
    {
        return ['1' => __('Expire_type 1'), '2' => __('Expire_type 2')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '0' => __('Status 0')];
    }


    public function getCouponTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['coupon_type']) ? $data['coupon_type'] : '');
        $list = $this->getCouponTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getExpireTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['expire_type']) ? $data['expire_type'] : '');
        $list = $this->getExpireTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function store()
    {
        return $this->belongsTo('\\app\\admin\\model\\Store', 'store_id', 'id')->setEagerlyType(1);;
    }

    public function room()
    {
        return $this->belongsTo('\\app\\admin\\model\\Room', 'room_id', 'id')->setEagerlyType(1);;
    }

}
